/*
Realistic Unit Modification v4.0 Dialog 
v4.0.0.1 [ALPHA]
Concept & Development by Draper & Raps | [VRC]
*/


// IDD and IDC ------------------------

RUM_AHel_IDD = 1040;
RUM_BttnExit_IDC = 1041;
RUM_BttnAHel_IDC = 1042;
RUM_ListAHel_IDC = 1043;
RUM_BttnStrike_IDC = 1044;
RUM_AHel_STAT_IDD = 1045;

// Code -------------------------------

// Buttons ----------------------------

RUM_BttnAHel = {
	if (RUM_AHel_moveStation) exitwith {
		private["_arry","_helo"];
		_sel = lbCurSel RUM_ListAHel_IDC;
		_arry = RUM_AHelAircraft_onStation select _sel;
		if (RUM_AHEL_NonSpawn) then {
			_helo = _arry select 0;
		} else {
			_num = count _arry;
			_helo = _arry select (_num - 1);
		};
		[_helo,_arry select 1] execVM (RUM_PATH+"AHel\moveStation.sqf");
		RUM_AHel_moveStation = false;
		closeDialog 0;
	};
	if (RUM_AHel_ATGM) exitwith {
		private["_arry","_helo"];
		_sel = lbCurSel RUM_ListAHel_IDC;
		_arry = RUM_AHelAircraft_onStation select _sel;
		if (RUM_AHEL_NonSpawn) then {
			_helo = _arry select 0;
		} else {
			_num = count _arry;
			_helo = _arry select (_num - 1);
		};
		_callsign = _arry select 1;
		RUM_AHel_ATGM = false;
		_gunnum = _arry find "atgm";
		if (!(_gunnum == -1)) then {
			_gunweap = _arry select (_gunnum + 1);
			_class = _arry select 2;
			[_gunweap,_helo,_callsign,"ATGM",_class] execVM (RUM_PATH+"AHel\weaponFire.sqf");
		} else {
			hint "ATGM Strikes are not Authorized";
		};
		closeDialog 0;
	};
	if (RUM_AHel_SFS) exitwith {
		private ["_arry","_helo"];
		_sel = lbCurSel RUM_ListAHel_IDC;
		_arry = RUM_AHelAircraft_onStation select _sel;
		if (RUM_AHEL_NonSpawn) then {
			_helo = _arry select 0;
		} else {
			_num = count _arry;
			_helo = _arry select (_num - 1);
		};
		_callsign = _arry select 1;
		RUM_AHel_SFS = false;
		_gunnum = _arry find "sfs";
		if (!(_gunnum == -1)) then {
			_gunweap = _arry select (_gunnum + 1);
			_class = _arry select 2;
			[_gunweap,_helo,_callsign,"SFS",_class] execVM (RUM_PATH+"AHel\weaponFire.sqf");
		} else {
			hint "SFS Strikes are not Authorized";
		};
		closeDialog 0;
	};
	if (RUM_AHEL_NonSpawn) then {
		if (RUM_AHel_Strike) then {
			if (RUM_AHEL_idleorstation) then {
				_arry = [];
				_sel = lbCurSel RUM_ListAHel_IDC;
				_arry = RUM_AHelAircraft select _sel;
				_arry execVM (RUM_PATH+"AHel\callCAS.sqf");
				// this will delete the vehicle from the RUM PDA when selected for use.
				RUM_AHelAircraft set [_sel,"del"];
				RUM_AHelAircraft = RUM_AHelAircraft - ["del"];
			} else {
				_sel = lbCurSel RUM_ListAHel_IDC;
				_arry = RUM_AHelAircraft_onStation select _sel;
				_helo = _arry select 0;
				_callsign = _arry select 1;
				_home = _arry select 2;
				_airport = _arry select 3;
				_egress = _arry select 4;
				_ingress = _arry select 5;
				[_helo,_airport,_egress,_ingress,_home,_callsign] execVM (RUM_PATH+"AHel\callCASStat.sqf");
			};
		} else {
			if (RUM_AHEL_idleorstation) then {
				_arry = [];
				_sel = lbCurSel RUM_ListAHel_IDC;
				_arry = RUM_AHelAircraft select _sel;
				[_arry] execVM (RUM_PATH+"AHel\onStation.sqf");
				// this will delete the vehicle from the RUM PDA when selected for use.
				RUM_AHelAircraft set [_sel,"del"];
				RUM_AHelAircraft = RUM_AHelAircraft - ["del"];
			} else {
				_sel = lbCurSel RUM_ListAHel_IDC;
				_arry = RUM_AHelAircraft_onStation select _sel;
				_arry execVM (RUM_PATH+"AHel\rtb.sqf");
				// this will delete the stationed vehicle from the RUM PDA when selected for use.
				RUM_AHelAircraft_onStation set [_sel,"del"];
				RUM_AHelAircraft_onStation = RUM_AHelAircraft_onStation - ["del"];
			};
		};
	} else {
		if (RUM_AHel_Strike) then {
			if (RUM_AHEL_idleorstation) then {
				_arry = [];
				_sel = lbCurSel RUM_ListAHel_IDC;
				_arry = RUM_AHelAircraft_Spawn select _sel;
				_helo = _arry select 0;
				_callsign = _arry select 1;
				_class = _arry select 2;
				_spwn = _arry select 3;
				[_helo,_class,_spwn,_callsign] execVM (RUM_PATH+"AHel\callCAS_spwn.sqf");
			} else {
				_sel = lbCurSel RUM_ListAHel_IDC;
				_arry = RUM_AHelAircraft_onStation select _sel;
				_arry execVM (RUM_PATH+"AHel\callCASStat_spwn.sqf");
			};
		} else {
			if (RUM_AHEL_idleorstation) then {
				_arry = [];
				_sel = lbCurSel RUM_ListAHel_IDC;
				_arry = RUM_AHelAircraft_Spawn select _sel;
				_arry execVM (RUM_PATH+"AHel\onStation_spwn.sqf");
				RUM_AHelAircraft_Spawn set [_sel,"del"];
				RUM_AHelAircraft_Spawn = RUM_AHelAircraft_Spawn - ["del"];
			} else {
				_sel = lbCurSel RUM_ListAHel_IDC;
				_arry = RUM_AHelAircraft_onStation select _sel;
				_arry execVM (RUM_PATH+"AHel\rtb_spwn.sqf");
				RUM_AHelAircraft_onStation set [_sel,"del"];
				RUM_AHelAircraft_onStation = RUM_AHelAircraft_onStation - ["del"];
			};
		};
	};
	publicVariable "RUM_AHelAircraft";
	publicVariable "RUM_AHelAircraft_Spawn";
	publicVariable "RUM_AHelAircraft_onStation";
	if(true)exitwith{closeDialog 0};
};

RUM_BttnStrike = {
	_id = _this select 1;
	switch (_id) do {
		case 0: {
			RUM_AHel_Strike = true;
		};
		case 1: {
			RUM_AHel_Strike = false;
		};
		case 2: {
			RUM_AHel_moveStation = true;
		};
		case 3: {
			RUM_AHel_ATGM = true;
		};
		case 4: {
			RUM_AHel_SFS = true;
		};
	};
	if (true) exitwith {};
};

RUM_AHel_Stationed = {
	closedialog 0;
	[player] execVM (RUM_PATH+"AHel\RUM_AHel.sqf");
	if (true) exitwith {};
};

// Lists ------------------------------

RUM_FillListAHel1 = {
	lbClear RUM_ListAHel_IDC;
	_list1 = [];
	_airlist = [];
	if (RUM_AHel_NonSpawn) then {
		_airlist = RUM_AHelAircraft;
	} else {
		_airlist = RUM_AHelAircraft_Spawn;
	};
	for [{_n = 1},{_n <= (count _airlist)},{_n = _n + 1}] do {
		_air = _airlist select (_n-1);
		_text = _air select 1;
		_list1 = _list1 + [_text];
   	};
	{lbAdd [RUM_ListAHel_IDC,_x]} foreach _list1;
	lbSetCurSel [RUM_ListAHel_IDC,0];
	if (true) exitWith {};
};

RUM_FillListAHel2 = {
	lbClear RUM_ListAHel_IDC;
	_list1 = [];
	_airlist = RUM_AHelAircraft_onStation;
	for [{_n = 1},{_n <= (count _airlist)},{_n = _n + 1}] do {
		_air = _airlist select (_n-1);	
		_text = _air select 1;
		_list1 = _list1 + [_text];
   	};
	{lbAdd [RUM_ListAHel_IDC,_x]} foreach _list1;
	lbSetCurSel [RUM_ListAHel_IDC,0];
	if (true) exitWith {};
};

// Start ------------------------------
RUM_AHel_Start = {
	RUM_AHel_Strike = true;
	RUM_AHel_moveStation = false;
	if (RUM_AHEL_idleorstation) then {
		call RUM_FillListAHel1;
	} else {
		call RUM_FillListAHel2;
	};
	if (true) exitwith {};
};

// Init -------------------------------
if (RUM_AHEL_idleorstation) then {
	call RUM_fn_ppEffect_dialog;
	createDialog "RUM_AHel"; 
};
if (!RUM_AHEL_idleorstation) then {
	call RUM_fn_ppEffect_dialog;
	createDialog "RUM_AHel_STAT";
};
call RUM_AHel_Start;

if (true) exitwith {};